/*     Copyright (c) 2018, jymenu.com. All rights reserved.   */
package com.yunhaikeji.core.security;

import com.alibaba.fastjson.JSON;
import com.yunhaikeji.core.web.ProcessResult;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * GoAccessDeniedHandler
 *
 * @author : zhuo
 * @date : 2018/7/18 23:06
 * @description :
 */
public class GoAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        httpServletResponse.setHeader("Content-Type", "application/json;charset=utf-8");
        ProcessResult processResult = ProcessResult.error("权限不足，不能进行该操作").setCode(HttpServletResponse.SC_FORBIDDEN + "");
        httpServletResponse.getWriter().print(JSON.toJSONString(processResult));
        httpServletResponse.getWriter().flush();
    }
}
